package br.ugf.projeto.util;

import java.util.MissingResourceException;
import java.util.ResourceBundle;

/**
 * <p>
 * </p>
 * 
 * @author Rodrigo Souza
 * @version 1.0 Created on Jun 2, 2008
 */
public class PropertiesHandler
{

	/**
	 * <p>
	 * Field <code>bundleName</code>
	 * </p>
	 */
	private static String bundleName;

	/**
	 * <p>
	 * Field <code>DEFAULT_SEPARATOR</code>
	 * </p>
	 */
	private static final String DEFAULT_SEPARATOR = "\t";

	/**
	 * <p>
	 * Field <code>resourceBundle</code>
	 * </p>
	 */
	private static ResourceBundle resourceBundle;

	/**
	 * <p>
	 * </p>
	 * 
	 * @return
	 */
	public static String getResourceBundleName()
	{
		return bundleName;
	}

	/**
	 * <p>
	 * </p>
	 * 
	 * @param key
	 * @return
	 */
	public static String getString( final String key )
	{
		try
		{
			return resourceBundle.getString( key );
		}
		catch ( MissingResourceException exception )
		{
			System.err.println( new StringBuilder( "PropertiesHanlder :: getString -> " ).append( exception ) );
		}

		return null;
	}

	/**
	 * <p>
	 * </p>
	 * 
	 * @param key
	 * @return
	 */
	public static String[] getStringArray( final String key )
	{
		try
		{
			return resourceBundle.getString( key ).split( DEFAULT_SEPARATOR );
		}
		catch ( MissingResourceException exception )
		{
			System.err.println( new StringBuilder( "PropertiesHanlder :: getString -> " ).append( exception ) );
		}

		return null;
	}

	/**
	 * <p>
	 * </p>
	 * 
	 * @param key
	 * @param separator
	 * @return
	 */
	public static String[] getStringArray( final String key, final String separator )
	{
		try
		{
			return resourceBundle.getString( key ).split( separator );
		}
		catch ( MissingResourceException exception )
		{
			System.err.println( new StringBuilder( "PropertiesHanlder :: getString -> " ).append( exception ) );
		}

		return null;
	}

	/**
	 * <p>
	 * </p>
	 * 
	 * @param aBundleName
	 */
	public static void setResourceBundle( final String aBundleName )
	{
		resourceBundle = ResourceBundle.getBundle( aBundleName );
	}

}